]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
main: Make sure that --mode parameter is valid
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 18 May 2012 21:57:04 +0000 (23:57 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 22 May 2012 17:42:27 +0000 (19:42 +0200)
Instead of falling back to a set of default values or crashing the
window manager when an invalid mode is specified, check the value
of the ShellGlobal:session-mode property before taking over as WM
and make a clean exit if it cannot be resolved to an existent mode.

https://bugzilla.gnome.org/show_bug.cgi?id=676156

js/ui/sessionMode.js
src/main.c
src/shell-global-private.h
src/shell-global.c

index 0cc2c14f954c50168383b73d00d19ec5592d5ca0..1ed5aaa21b1af302ae0e7b012be37ec0f42f0cbe 100644 (file)
@@ -13,6 +13,11 @@ const _modes = {
     'user': { sessionType: Shell.SessionType.USER }
 };
 
+function modeExists(mode) {
+    let modes = Object.getOwnPropertyNames(_modes);
+    return modes.indexOf(mode) != -1;
+}
+
 const SessionMode = new Lang.Class({
     Name: 'SessionMode',
 
index bd3b128b015d25163e1e853aaf1a38ffab45c2a1..97ad90af2354b477d3f65382a491b37a2ac01542 100644 (file)
@@ -335,6 +335,12 @@ main (int argc, char **argv)
 
   _shell_global_init ("session-mode", session_mode, NULL);
 
+  if (!_shell_global_has_valid_session_mode (shell_global_get ()))
+    {
+      g_printerr ("\"%s\" is not a valid mode.\n", session_mode);
+      exit(1);
+    }
+
   ecode = meta_run ();
 
   if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP"))
index 62f7c2603d83d29927e740b6a03264484786f10c..45e204ff3431e8514a53b534caa3efdb567ca34b 100644 (file)
@@ -13,6 +13,7 @@ void _shell_global_set_plugin      (ShellGlobal  *global,
 
 GjsContext *_shell_global_get_gjs_context (ShellGlobal  *global);
 
+gboolean _shell_global_has_valid_session_mode (ShellGlobal *global);
 gboolean _shell_global_check_xdnd_event (ShellGlobal  *global,
                                          XEvent       *xev);
 
index 01950190cf31b57808215ed528f727224ae77343..bc5a5c16db5190f004abe7011ab381658ab93d3e 100644 (file)
@@ -597,6 +597,21 @@ shell_global_set_stage_input_mode (ShellGlobal         *global,
     }
 }
 
+gboolean
+_shell_global_has_valid_session_mode (ShellGlobal *global)
+{
+  char *script;
+  int status;
+
+  script = g_strdup_printf ("imports.ui.environment.init();"
+                            "imports.ui.sessionMode.modeExists('%s') || 1;",
+                            global->session_mode);
+  gjs_context_eval (global->js_context, script, -1, "<sessionMode.js>", &status, NULL);
+  g_free (script);
+
+  return status == 0;
+}
+
 /**
  * shell_global_set_cursor:
  * @global: A #ShellGlobal